<template>
  <div class="employee-container">
    <el-row class="employee-header">
      <el-card>
        <el-form label-width="auto" :model="form">
          <el-row type="flex" justify="space-between">
            <el-form-item label="司机账号">
              <el-col :span="8">
                <el-input
                  v-model="form.account"
                  class="inputStyle"
                  placeholder="请输入司机账号"
                />
              </el-col>
            </el-form-item>
            <el-form-item label="司机姓名">
              <el-col :span="8">
                <el-input
                  v-model="form.name"
                  class="inputStyle"
                  placeholder="请输入司机姓名"
                />
              </el-col>
            </el-form-item>
            <el-form-item label="司机手机号">
              <el-col :span="8">
                <el-input
                  v-model="form.phone"
                  class="inputStyle"
                  placeholder="请输入司机手机号"
                />
              </el-col>
            </el-form-item>
          </el-row>
          <el-row type="flex">
            <el-form-item style="margin: 0" label="所属地区">
              <tree-data ref="treeData" v-model="form.agentId" />
            </el-form-item>
            <el-form-item style="margin: 0">
              <el-button
                class="buttonStyle"
                type="primary"
                size="small"
                @click="searchClick"
              >查询</el-button>
              <el-button
                class="buttonStyle"
                size="small"
                @click="resetClick"
              >重置</el-button>
            </el-form-item>
          </el-row>
        </el-form>
      </el-card>
    </el-row>
    <el-row class="employee-footer">
      <el-card class="footer-card">
        <el-row>
          <el-table :data="tableData" stripe style="width: 100%">
            <el-table-column align="center" prop="date" label="序号" width="50">
              <template slot-scope="scope">
                <span>{{ scope.$index + 1 }}</span>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              prop="account"
              label="司机账号"
              width="165.3"
            />
            <el-table-column
              align="center"
              prop="name"
              label="司机姓名"
              width="165.3"
            />
            <el-table-column
              align="center"
              prop="mobile"
              label="司机电话"
              width="165.3"
            />
            <el-table-column
              align="center"
              prop="truck.licensePlate"
              label="关联车辆"
              width="165.3"
            />
            <el-table-column
              align="center"
              prop="agency.name"
              label="所属机构"
              width="165.3"
            />
            <el-table-column
              align="center"
              prop="workStatus"
              label="工作状态"
              width="165.3"
            >
              <template #default="{ row }">
                <el-row type="flex" justify="center" align="middle">
                  <span
                    :class="{
                      'off-duty-dot': !row.workStatus,
                      'be-on-duty-dot': row.workStatus,
                    }"
                  />
                  <span>{{ row.workStatus ? "上班" : "下班" }}</span>
                </el-row>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              prop="address"
              label="操作"
              fixed="right"
              width="165.3"
            >
              <template #default="{ row }">
                <el-row type="flex" align="middle" justify="center">
                  <el-button
                    type="text"
                    size="small"
                    @click="examineClick(row)"
                  >查看</el-button>
                  <div class="centerLine" />
                  <el-button type="text" size="small" @click="configurationClick">配置车辆</el-button>
                </el-row>
              </template>
            </el-table-column>
            <template slot="empty">
              <el-empty :image-size="150" description="暂无数据" />
            </template>
          </el-table>
        </el-row>
        <el-row
          type="flex"
          justify="center"
          style="margin-top: 10px; height: 40px"
          align="middle"
        >
          <el-pagination
            :current-page="form.page"
            :page-sizes="[10, 20, 30, 40]"
            :page-count="pages"
            :page-size="form.pageSize"
            :pager-count="7"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            @size-change="sizeChange"
            @current-change="gurrentChange"
          />
        </el-row>
      </el-card>
    </el-row>
  </div>
</template>

<script>
import { getDriverAPI } from '@/api/employee'
import TreeData from '@/components/TreeData/index'
export default {
  components: {
    TreeData
  },
  data() {
    return {
      // 表单数据
      form: {
        page: 1,
        pageSize: 10,
        account: '',
        name: '',
        agentId: '',
        phone: '',
        workStatus: ''
      },
      // 表格数据
      tableData: [],
      // 总条数
      total: 0,
      // 总页数
      pages: 1
    }
  },
  created() {
    this.tableListData()
  },
  methods: {
    // 司机列表
    async tableListData() {
      const { data } = await getDriverAPI(this.form)
      const itemData = data.data
      this.tableData = itemData.items
      this.total = +itemData.total
      this.pages = +itemData.pages
    },
    // 查询
    searchClick() {
      clearTimeout(this.timer)
      this.timer = setTimeout(() => {
        this.tableListData()
      }, 500)
    },
    // 重置
    resetClick() {
      this.form.account = null
      this.form.name = null
      this.form.agentId = null
      this.form.phone = null
      this.form.workStatus = null
      this.$refs.treeData.backups.agentName = null
      clearTimeout(this.timer)
      this.timer = setTimeout(() => {
        this.tableListData()
      }, 500)
    },
    // 查看
    examineClick({ userId }) {
      this.$router.push({
        path: '/employee/driverDetail/' + userId
      })
    },
    // 配置车辆
    configurationClick() {
      // this.$router.push({
      //   path: '/employee/driverConfiguration'
      // })
    },
    // 当前页条数改变
    sizeChange(pageSize) {
      this.form.pageSize = pageSize
    },
    // 当前页改变
    gurrentChange(page) {
      this.form.page = page
    }
  }
}
</script>

<style scoped lang="scss">
.employee-container {
  padding: 0 20px;

  .employee-header {
    font-size: 13px;
    margin-bottom: 20px;
    .el-form-item {
      padding: 0 20px;
      .inputStyle {
        width: 270px;
      }
      .buttonStyle {
        width: 80px;
        height: 30px;

        &.buttonStyle:first-child {
          background-color: #189450;
          border-color: #189450;
          margin-right: 10px;

          &:hover {
            opacity: 0.7;
          }
        }
      }
    }
    .header-footer {
      margin: 0;
    }
  }
  .employee-footer {
    .footer-card {
      padding: 10px;
      padding-bottom: 0;

      .off-duty-dot {
        display: inline-block;
        width: 5px;
        height: 5px;
        background-color: #ff4d4f;
        border-radius: 50%;
        margin-right: 5px;
      }
      .be-on-duty-dot {
        display: inline-block;
        width: 5px;
        height: 5px;
        background-color: #189450;
        border-radius: 50%;
        margin-right: 5px;
      }
    }
  }
}

.centerLine {
  box-sizing: border-box;
  margin: 0 10px;
  width: 1px;
  height: 13px;
  background: #d0d3da;
}
::v-deep .el-form-item__label {
  font-size: 13px;
}

::v-deep .el-table thead tr th {
  font-size: 13px;
  font-weight: bold;
  background: #f8faff !important;
  border: none;
}
::v-deep .el-table tbody tr td {
  font-size: 13px;
  color: #606266;
  border: none;
}
::v-deep .el-input__inner {
  height: 35px;
  font-size: 13px;
}
::v-deep .el-pagination .el-select .el-input .el-input__inner {
  height: 28px;
  font-size: 13px;
}
// // test
// .tree {
//   padding: 0;
//   height: auto;
//   overflow: auto;
//   // 滚动条
//   &::-webkit-scrollbar {
//     width: 5px;
//     height: 5px;
//   }
// }
</style>
